package com.marion.study.aop.pattern.dynamicproxy;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;


public class CglibDynamicProxy implements MethodInterceptor {

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

        System.out.println("[CglibDynamicProxy] start ...");
        Object result;
        try {
            result = methodProxy.invokeSuper(o, objects);
        } catch (Exception e) {
            System.out.println("[CglibDynamicProxy] " + e.getMessage());
            throw e;
        } finally {
            System.out.println("[CglibDynamicProxy] end ...");
        }

        return result;
    }

}
